<?php

namespace app\index\controller;

use think\Db;
use app\common\model\ManagerCompany as ManagerCompanyModel;
use app\common\model\ManagerPassword as ManagerPasswordModel;
/**
 * 修改密码控制器
 * Class Index
 * @package app\index\controller
 */
class ManagerPassword extends Base
{
    /**
     * [postEdit  修改密码]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function postEdit()
    {
        $param = input('param.');
        $user = $this->user;
        $model = new ManagerPasswordModel();
        $map = [];
        try{
            $mpass = $model->getOne(['comid'=>$user['comid'],'mid'=>$user['mid']],'id','id,password');
            if($mpass['password'] != md5(md5($param['password']) . config('index.manager_password_halt'))){
                return admin_json(-2, '原密码错误！');
            }
            $model->editData(['id'=>$mpass['id'],'password'=>md5(md5($param['npassword']) . config('index.manager_password_halt')),'pass'=>$param['npassword']]);
        }catch(\Exception $e){
            systembug($e->getMessage(),3,$this->url);
            return admin_json(-1, '修改失败'.$e->getMessage());
        }
        return admin_json(1, '修改成功');
    }
    /**
     * [postStatus  修改状态]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function postStatus()
    {
        $param = input('param.');
        $user = $this->user;
        $model = new ManagerCompanyModel();
        $mpmodel = new ManagerPasswordModel;
        try{
            $model->changeStatus(['comid'=>$user['comid'],'mid'=>$param['mid']],$param['status']);
            $mpmodel->changeStates(['comid'=>$user['comid'],'mid'=>$param['mid']],$param['status']);
        }catch(\Exception $e){
            systembug($e->getMessage(),3,$this->url);
            return admin_json(-1, '修改失败'.$e->getMessage());
        }
        return admin_json(1, '修改成功');
    }
    /**
     * [postStatus  修改状态]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function postStatus1()
    {
        $param = input('param.');
        $user = $this->user;
        $mpmodel = new ManagerPasswordModel;
        try{
            $mpass = $mpmodel->getOne(['comid'=>$user['comid'],'mid'=>$param['mid']],'id','states');
            if(!empty($mpass)){
                if($mpass['states'] == 1){
                    $mpmodel->changeStates(['comid'=>$user['comid'],'mid'=>$param['mid']],-1);
                }else{
                    $mpmodel->changeStates(['comid'=>$user['comid'],'mid'=>$param['mid']],1);
                }

            }
        }catch(\Exception $e){
            systembug($e->getMessage(),3,$this->url);
            return admin_json(-1, '修改失败'.$e->getMessage());
        }
        return admin_json(1, '修改成功');
    }
}